package org.niit.dao

import org.apache.spark.sql.catalyst.expressions.aggregate.Count
import org.niit.util.JDBCUtil

class ZhangRealTimeDao {

  //一：不同时间观看数量分布  ---->    表timeusersum
//  def insertTimeUserSum(h: String,count:Int):Unit ={
//
//    val conn = JDBCUtil.getConnection
//
//    JDBCUtil.executeUpdate(conn,
//
//      "INSERT INTO timeusersum (h, count) VALUES (?, ?) on duplicate key update count = count + ?",
//      Array(h,count,count)
//    )
//
//    conn.close()
//
//  }

  //二：不同地区用户数量分布   ---->   表timecitysum
//  def insertTimeCitySum(city:String,count:Int):Unit = {
//
//    val conn = JDBCUtil.getConnection
//
//    JDBCUtil.executeUpdate(conn,
//
//      "INSERT INTO timecitysum (city, count) VALUES (?, ?) on duplicate key update count = count + ?",
//      Array(city,count,count)
//    )
//
//    conn.close()
//
//  }

  //四：一周内的播放分布  ----->   表timeweeksum
//  def insertTimeWeekSum(day:String,count: Int) :Unit = {
//    val conn = JDBCUtil.getConnection
//
//    JDBCUtil.executeUpdate(conn,
//
//      "INSERT INTO timeweeksum (day, count) VALUES (?, ?) on duplicate key update count = count + ?",
//      Array(day,count,count)
//    )
//
//    conn.close()
//  }

  //五：不同用户价值判断  ----->   表

  // 一、实时监测每5秒新用户占比变化  ---->  表zhangTime1
  def insertTime1(device:String,count:Int): Unit = {
    val conn = JDBCUtil.getConnection

    JDBCUtil.executeUpdate(conn,
      """
        |INSERT INTO zhangTime1 (device,count) VALUES (?, ?) on duplicate key update count = count + ?
        |""".stripMargin,
      Array(device,count,count)
    )

    conn.close()
  }

  //二、不同设备用户三步行为统计
  def insertTime2(device:String,homeTotal:String, threeStepTotal:String, rate:String): Unit = {
    val conn = JDBCUtil.getConnection

    JDBCUtil.executeUpdate(conn,
      """
        |INSERT INTO zhangTime2 (device, homeTotal, threeStepTotal, rate) VALUES (?, ?, ?, ?)
        |""".stripMargin,
      Array(device, homeTotal, threeStepTotal, rate)
    )

    conn.close()
  }

  //三、不同用户在不同设备完成支付的实时支付率
  def insertTime3(userType:String, os:String, productTotal:String, paymentTotal:String, rate:String): Unit = {
    val conn = JDBCUtil.getConnection

    JDBCUtil.executeUpdate(conn,
      """
        |INSERT INTO zhangTime3 (userType, os, productTotal, paymentTotal, rate) VALUES (?, ?, ?, ?, ?)
        |""".stripMargin,
      Array(userType, os, productTotal, paymentTotal, rate)
    )

    conn.close()
  }

  //四、不同性别年龄用户访问列表页的实时次数
  def insertTime4(sex:String,ageGroup:String, totalUsers:String, listingUsers:String, avgVisits:String): Unit = {
    val conn = JDBCUtil.getConnection

    JDBCUtil.executeUpdate(conn,
      """
        |INSERT INTO zhangTime4 (sex, ageGroup, totalUsers, listingUsers, avgVisits) VALUES (?, ?, ?, ?, ?)
        |""".stripMargin,
      Array(sex, ageGroup, totalUsers, listingUsers, avgVisits)
    )

    conn.close()
  }

  //五、用户在不同来源不同设备的产品页次数
  def insertTime5(source:String,device:String, totalUsers:String, r0_5:String, r6_10:String, r11Plus:String): Unit = {
    val conn = JDBCUtil.getConnection

    JDBCUtil.executeUpdate(conn,
      """
        |INSERT INTO zhangTime5 (source, device, totalUsers, r0_5, r6_10, r11Plus) VALUES (?, ?, ?, ?, ?, ?)
        |""".stripMargin,
      Array(source, device, totalUsers, r0_5, r6_10, r11Plus)
    )

    conn.close()
  }

  //六、不同用户在不同市场的支付率
  def insertTime6(market:String,os:String, totalUsers:String, failureRate:String): Unit = {
    val conn = JDBCUtil.getConnection

    JDBCUtil.executeUpdate(conn,
      """
        |INSERT INTO zhangTime6 (market, os, totalUsers,failureRate) VALUES (?, ?, ?, ?)
        |""".stripMargin,
      Array(market, os, totalUsers,failureRate)
    )

    conn.close()
  }





}
